/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */

import { DepartmentsVo } from "@/modules/departments/api/departments";
import type { MaFormItem } from "@mineadmin/form";
import type { QuestionGroupVo } from "~/question/api/group.ts";
import {
  question_types,
  levels,
  type QuestionVo,
} from "~/question/api/question";
import { page } from "~/question/api/group";
//@ts-ignore
import RemoteSelect from "@/components/ma-remote-select/index.vue";
//@ts-ignore
import Editor from "@/components/fy-editor/index.vue";
import { ElRadio, ElRadioButton, ElRadioGroup } from "element-plus";
//@ts-ignore
import Answer from "../components/answer.vue";
export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: QuestionVo
): MaFormItem[] {
  if (formType === "add") {
    model.level = 1;
    model.type = "choice";
  }
  console.log(model);
  return [
    {
      label: () => t("question-manage.group"),
      prop: "group_id",
      render: () => RemoteSelect,
      renderProps: {
        placeholder: t("form.pleaseSelect", {
          msg: t("question-manage.group"),
        }),
        api: () => new Promise((resolve) => resolve(page({ page_size: 999 }))),
        dataHandle: (response: any) => {
          return response.data.list?.map((item: QuestionGroupVo) => {
            return { label: `${item.name}`, value: item.id };
          });
        },
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredSelect", {
              msg: t("question-manage.group"),
            }),
          },
        ],
      },
    },
    {
      label: () => t("question-manage.type"),
      prop: "type",
      render: () => (
        <ElRadioGroup>
          {question_types.map((item) => (
            <ElRadioButton label={item.name} value={item.code}></ElRadioButton>
          ))}
        </ElRadioGroup>
      ),

      renderProps: {
        placeholder: t("form.pleaseSelect", {
          msg: t("question-manage.type"),
        }),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.pleaseSelect", {
              msg: t("question-manage.type"),
            }),
          },
        ],
      },
    },
    {
      label: () => t("question-manage.level"),
      prop: "level",
      render: () => (
        <ElRadioGroup>
          {levels.map((item) => (
            <ElRadioButton label={item.name} value={item.level}></ElRadioButton>
          ))}
        </ElRadioGroup>
      ),

      renderProps: {
        placeholder: t("form.pleaseSelect", {
          msg: t("question-manage.level"),
        }),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.pleaseSelect", {
              msg: t("question-manage.level"),
            }),
          },
        ],
      },
    },
    {
      label: () => t("question-manage.question"),
      prop: "title",
      render: () => Editor,
      renderProps: {
        placeholder: t("form.pleaseInput", {
          msg: t("question-manage.question"),
        }),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredInput", {
              msg: t("question-manage.question"),
            }),
          },
        ],
      },
    },
    {
      label: () => t("question-manage.answers"),
      prop: "answers",
      render: () => Answer,
      renderProps: {
        placeholder: t("form.pleaseInput", {
          msg: t("question-manage.answers"),
        }),
        model,
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredInput", {
              msg: t("question-manage.answers"),
            }),
          },
        ],
      },
    },
  ];
}
